package sy.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import sy.pageModel.UserAction;
import sy.service.UserActionServiceI;

@Service("userActionService")
public class UserActionServiceImpl implements UserActionServiceI {
	
	@Autowired
    private JdbcTemplate template;

	public UserAction add(UserAction userAction) throws Exception {
		String sql = "insert into tuser_actions (user_id, user_name, user_ip, create_time, action, details) " + 
	             "values(?, ?, ?, ?, ?, ?)";
	
	    Object[] paras = new Object[] {
	    		userAction.getUserId(),
	    		userAction.getUserName(),
	    		userAction.getUserIP(),
	    		userAction.getCreateTime(),
	    		userAction.getAction(),
	    		userAction.getDetails()
	    };
	
		int affectRow = 0;
		try {
		    affectRow = template.update(sql, paras);
		} catch(Exception e) {
			e.printStackTrace();
			throw new RuntimeException("添加会员失败，请联系系统管理员！");
		}
		if(affectRow == 0) {
			throw new RuntimeException("添加会员失败，请联系系统管理员！");
		}
		return userAction;
	}
}
